package com.example.softwareconfigurationcoursedesign;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet( "/addProduct")
public class AddProductServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 从请求参数获取商品信息
        String productName = request.getParameter("productName");
        double productPrice = Double.parseDouble(request.getParameter("productPrice"));
        String productTag = request.getParameter("productTag");
        String productDetail = request.getParameter("productDetail");

        // 在数据库中插入商品信息
        ProductService productService = new ProductService();
        productService.addProduct(productName, productPrice, productTag, productDetail);

        // 输出商品信息到控制台
        System.out.println("添加商品信息：");
        System.out.println("商品名称：" + productName);
        System.out.println("商品价格：" + productPrice);
        System.out.println("商品标签：" + productTag);
        System.out.println("商品详情：" + productDetail);

        System.out.println("添加商品");

//        // 重定向到商品列表页面
//        response.sendRedirect("Admin_Product.jsp");
    }
}

